<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配送关系管理</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>选择配送企业</h1>
        <ol class="breadcrumb">
           <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">配送关系</a></li>
            <li class="active"><a href="#">配送关系设置</a></li>
        </ol>
    </section>
    
		
		<section class="content">
        <div class=" box box-success">
            <div class="box-body">
            
                <div class="input">
                       <div class="textalign1">企业名称：</div>
                       <div class="boxinput">
                          <input class="textinput" type="text" id="compName" name="compName" placeholder="企业名称"  />
                       </div>
                
                       <div class="textalign">企业编码：</div>
                       <div class="boxinput">
                          <input class="textinput" type="text" id="compCode" name="compCode" placeholder="企业编码"  />
                       </div>
                      
                       <div class="textalign1">
                          <button id="selectSee" type="button" onclick="gridSerch();" class="btn btn-success btn-sm">查&nbsp;询</button>
                       </div>
                </div>
            
            
			</div>
		</div>
<div style="margin-top: 5px;"></div>
	<table class="jqgrid" id="gridlist"></table>
<div style="margin-top: 10px;"></div>
<div id="prowed2"></div>


<div class=" box box-warning bottongroup" id="bottongroup">
			<button id="buttonID" onclick="return setDel();" class="btn btn-primary btn-sm">提 交</button>
			<label  onclick="window.history.go(-1)"   class="btn btn-danger btn-sm" >返 回</label>
		</div>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">

//绑定回车   id="selectSee"
$('#compName,#compCode').bind('keydown', function(event) {
    if (event.keyCode == "13") {
        $('#selectSee').click();
    }
}); 
$("#compName").focus();//加载页面光标在第一个查询框内

function setDel(){
		  $("#buttonID").attr("disabled",true);
		  setTimeout( function fun(){
				$("#buttonID").attr("disabled",false);
			 },2000);
		    var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
			if (rowIds.length <= 0) {
				$.HN.message.alert("请选择要提交的企业！", "消息", "warn");
				return;
			}
			var delRange = "";
			var goodsCode = '${param.goodsCode}';
			var areaCode = '${param.areaId}';
			var list = [];
			var compNames="";
			for (var i=0; i<rowIds.length; i++) {
				rowId = rowIds[i];
				var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
				if("${type}"=="1"){
					delRange = $("#del"+rowId).val();
				}else{
					if($("#j"+rowId).prop("checked")&&$("#x"+rowId).prop("checked")){
						delRange = "0";
					}else if(!$("#j"+rowId).prop("checked")&&$("#x"+rowId).prop("checked")){
						delRange = "1";
					}else if($("#j"+rowId).prop("checked")&&!$("#x"+rowId).prop("checked")){
						delRange = "2";
					}
				}
				list.push({
		    		"delCompCode":rowdata.compCode,
		    		"delRange":delRange	
				});
				if(3>i){
					compNames+=rowdata.compName+"<br/>";
					if(2==i){
						compNames+="..";	
					}
				}
			}
			$.HN.message.confirm("确定要提交以下企业吗？<br/>"+compNames, '', '').on(function (e) {
	            if (e) {
			$.post("${pageContext.request.contextPath}/baseGoods/setDelByArea.html", {
				"array" : json.jsonToString(list),"areaCode":areaCode,"goodsCode":goodsCode
				}, function(result) {
					if (result.success) {
						$.HN.message.alert("成功操作"+list.length+"条数据！", "消息", "success");
						//window.location.href="${ctx}/baseGoods/toProDelDrugList.html";
						gridSerch();
					} else {
						$.HN.message.alert(result.msg, "消息", "error");
					}


				}, "json");
	            }
			});
   
}
$(document).ready(function (){
	jQuery("#gridlist").jqGrid({
		url: "${ctx}/baseGoods/getBaseGoodsDelByAreaList.html?areaId=${param.areaId}&goodsCode=${param.goodsCode}&projID=${param.projID}",
	    mtype: "POST",
		datatype: "json",
		autowidth: true,
		shrinkToFit: true,
	//	height: 292,
	   	colNames:['配送范围','企业编码','企业名称','组织机构代码','联系人','联系电话'],
	   	colModel:[
			{name:'delRange',index:'delRange',width:100,align:"center", sortable:false,
				formatter : function(cellvalue,opts,row){
					return "<input type='checkbox' id='j"+row.compCode+"'/>基层<input type='checkbox' id='x"+row.compCode+"'/>县及县以上<input type='hidden' id='del"+row.compCode+"' value='"+row.delRange+"'/>";
				}	
			},
	   		{name:'compCode',index:'compCode',width:100,align:"center", sorttype:false,sortable:false},
	   		{name:'compName',index:'compName',width:150,align:"center",sortable:false,sortable:false},
	   		{name:'orgCode',index:'orgCode',width:80, align:"center",sorttype:false,sortable:false},
	   		{name:'contactName',index:'contactName',width:80, align:"center",sorttype:false,sortable:false},
	   		{name:'contactTelephone',index:'contactTelephone',width:60,align:"center", sorttype:false,sortable:false}
	   	],
		gridComplete: function(){
			
		},
		 rowNum: 20,
	     rowList: [10, 20, 50,100],
	     rownumbers: true,
	     multiselect: true,
	     pager: "#prowed2",
	     viewrecords: true,
		 gridComplete: function(){
		//序号列宽度自适应（参数为jqgridID）
		 autoRNWidth("gridlist");
		//数据只有一条时默认选中（参数为jqgridID）
		 selectByOneData("gridlist");
		 },
	     caption: "${form.goods_code}/${form.qualityspec_name}/${form.form_name}/${form.spec_name}/${form.factor}/${form.unit_name}/${form.material_name}/${form.prod_compname}",
	     jsonReader: {
	         repeatitems: false,
	         id: "compCode"
	     }
	     
	   	
	});
	${linxuan==0?"":"$('#gridlist').hideCol('delRange');"}
	$(window).trigger("resize");
	$("#gridlist").jqGrid("setGridHeight", create());
});

function gridSerch(){
	var compCode = $.trim($("#compCode").val());
	var compName = $.trim($("#compName").val());
	$("#gridlist").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"compCode":compCode,
        		"compName":compName,
        		"areaId":"${param.areaId}",
        		"goodsCode":"${param.goodsCode}",
        		"projID":"${param.projID}"},
        		page:1
    }).trigger("reloadGrid"); //重新载入  
}

function gridAreaSerch(){
	var areaCode = $.trim($("#areaCode").val());
	var areaName = $.trim($("#areaName").val());
	$("#list5").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"areaCode":areaCode,
        		"areaName":areaName}
    }).trigger("reloadGrid"); //重新载入  
}
	    
</script>
</body>
</html>